﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using System.Windows.Data;
using System.IO;
using System.Windows.Threading;
using Qplus.Commands;

namespace Qplus.UI
{
    public partial class EntryPage : PhoneApplicationPage
    {
        l2cInfo l2c;
        protected Dictionary<string, object> userList = new Dictionary<string, object>();
        List<FriendControl> fList = new List<FriendControl>();
        List<ChatRoomControl> rList = new List<ChatRoomControl>();
        user[] friendListArr;
        List<friend> friendList = new List<friend>();
        room[] roomListArr;
        List<roomCtrl> roomList = new List<roomCtrl>();
        UIData uidata = UIData.getInstance();
        public EntryPage()
        {
            InitializeComponent();
            flist.ItemsSource = fList;
            //flist.ItemsSource = friendList;
            //friend search = new friend()
            //{
            //    type = friendCtrlTypeEnum.search
            //};
            //friendList.Insert(0, search);
            FriendControl search1 = new FriendControl()
            {
                CtrlType = friendCtrlTypeEnum.search,
            };
            fList.Insert(0, search1);
            FriendControl android = new FriendControl()
            {
                CtrlType = friendCtrlTypeEnum.friend,
                Type = 0,
                UserID = 10211,
            };
            fList.Insert(1, android);
            //UIData.getInstance().AddFriend(0, 10211);
            //friendItemsControl.ItemsSource = fList;
            rlist.ItemsSource = rList;
            //rlist.ItemsSource = roomList;
            //room create = new room()
            //{
            //    type = chatroomCtrlTypeEnum.create
            //};
            //roomList.Insert(0, create);
            ChatRoomControl create1 = new ChatRoomControl()
            {
                CtrlType = chatroomCtrlTypeEnum.create,
            };
            rList.Insert(0, create1);
        }
        #region ONLOAD
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            //getData();
            //System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.TryGetValue<l2cInfo>("l2cInfo", out l2c);
            //createFriendList();
            //createChatRoomList();
            #region
            //FriendControl frd1 = new FriendControl()
            //{
            //    UserID = friendList.userList[0].userID,
            //    UserName = friendList.userList[0].userName,
            //    UserLevel = friendList.userList[0].userLevel,
            //    HeadType = friendList.userList[0].headType,
            //    HeadValue = friendList.userList[0].headValue,

            //    Type = friendCtrlTypeEnum.friend,
            //    BtnExBackGround = new ImageBrush()
            //    {
            //        ImageSource = new BitmapImage(new Uri("/Qplus;component/Pic/app_info_default_icon.png", UriKind.RelativeOrAbsolute)),
            //        Stretch = Stretch.None,
            //    }
            //};
            //frd1.delFrndBtnEx.Click += delFriend;
            //userList.Add(frd1.UserID.ToString(), frd1);

    //        List<business> che = new List<business>()  
    //{  
    //   new business() { txt = "选项1"},  
    //   new business() { txt = "选项2"},  
    //   new business() { txt = "选项3"},  
    //   new business() { txt = "选项4"},  
    //   new business() { txt = "选项5"},  
    //   new business() { txt = "选项6"},  
    //   new business() { txt = "选项7"}                  
    //};
    //        friendWP.ItemsSource = che;
            //if (firstRun)
            //{
            //    friendLstTest();
            //    createFriendList(friendLklst);

            //    chatroomLstTest();
            //    createChatRoomList();

            //    strangerLstTest();
            //    createStrangerList(strangeLklst);
            //    firstRun = false;
            //}
            #endregion
            base.OnNavigatedTo(e);
        }
        #endregion
        #region TEST
        private void friendLstTest()
        {
            FriendControl search = new FriendControl()
            {
                UserID = 0,
                CtrlType = friendCtrlTypeEnum.search,
            };
            FriendControl frd1 = new FriendControl()
            {
                UserID = 1,
                CtrlType = friendCtrlTypeEnum.friend,
                UserName = "好友1",
                BtnExBackGround = new ImageBrush() 
                {
                    ImageSource = new BitmapImage(new Uri("/Qplus;component/Pic/app_info_default_icon.png", UriKind.RelativeOrAbsolute)),
                    Stretch = Stretch.None,
                }
            };
            frd1.delFrndBtnEx.Click += delFriend;
            FriendControl frd2 = new FriendControl()
            {
                UserID = 2,
                CtrlType = friendCtrlTypeEnum.friend,
            };
            frd2.delFrndBtnEx.Click += delFriend;
            FriendControl frd3 = new FriendControl()
            {
                UserID = 3,
                CtrlType = friendCtrlTypeEnum.friend,
                UserName = "好友3",
            };
            frd3.delFrndBtnEx.Click += delFriend;
            FriendControl frd4 = new FriendControl()
            {
                UserID = 4,
                CtrlType = friendCtrlTypeEnum.friend,
                UserName = "好友4",
            };
            frd4.delFrndBtnEx.Click += delFriend;
            friendLklst.AddFirst(search);
            friendLklst.AddLast(frd1);
            friendLklst.AddLast(frd2);
            friendLklst.AddLast(frd3);
            friendLklst.AddLast(frd4);
        }
        private void chatroomLstTest()
        {
            ChatRoomControl create = new ChatRoomControl()
            {
                CtrlType = chatroomCtrlTypeEnum.create,
            };
            create.chatRoomBtnEx.Click += createChatroomBtnEx_Click;
            ChatRoomControl Chatroom1 = new ChatRoomControl()
            {
            };
            ChatRoomControl Chatroom2 = new ChatRoomControl()
            {
                RoomName = "我的聊天室",
            };
            ChatRoomControl Chatroom3 = new ChatRoomControl()
            {
                HotStar = 3,
            };
            ChatRoomControl Chatroom4 = new ChatRoomControl()
            {
                bgImage = new ImageBrush()
                {
                    ImageSource = new BitmapImage(new Uri("/Qplus;component/Pic/dog.png", UriKind.RelativeOrAbsolute)),
                    Stretch = Stretch.None,
                }
            };
            chatroomLklst.AddLast(create);
            chatroomLklst.AddLast(Chatroom1);
            chatroomLklst.AddLast(Chatroom2);
            chatroomLklst.AddLast(Chatroom3);
            chatroomLklst.AddLast(Chatroom4);
        }
        private void strangerLstTest()
        {
            FriendControl stranger1 = new FriendControl()
            {
                UserID = 1,
                CtrlType = friendCtrlTypeEnum.stranger,
                UserName = "陌生人1",
            };
            FriendControl stranger2 = new FriendControl()
            {
                UserID = 2,
                CtrlType = friendCtrlTypeEnum.stranger,
                UserName = "陌生人2",
            };
            FriendControl stranger3 = new FriendControl()
            {
                UserID = 3,
                CtrlType = friendCtrlTypeEnum.stranger,
                UserName = "陌生人3",
            };
            FriendControl stranger4 = new FriendControl()
            {
                UserID = 4,
                CtrlType = friendCtrlTypeEnum.stranger,
                UserName = "陌生人4",
            };
            strangeLklst.AddLast(stranger1);
            strangeLklst.AddLast(stranger2);
            strangeLklst.AddLast(stranger3);
            strangeLklst.AddLast(stranger4);
        }
        #endregion
        #region FRIEND
        public LinkedList<FriendControl> friendLklst = new LinkedList<FriendControl>();
        public bool createFriendList()
        {
            //System.IO.IsolatedStorage.IsolatedStorageSettings settings = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings;
            //settings.TryGetValue<user[]>("userList", out friendListArr);
            //beans.UserInfo friend = new beans.UserInfo();
            //Qplus.Commands.GetFriendCommand command_GetFriend = new Commands.GetFriendCommand(
            //    l2c.UserID.ToString(),System.Text.Encoding.UTF8.GetString(l2c.Key,0,l2c.Key.Length),friend);
            var userNode=uidata.userList.list.First;
            while(null!=userNode)
            {
                #region
                //Qplus.Commands.GetResCommand command_GetFriendRes = new Qplus.Commands.GetResCommand(
                //    friendList[i].userID.ToString(),
                //    friendList[i].headValue);
                //command_GetFriendRes.execute(l2c.UpgradeURL);
                //Qplus.beans.Session session = new Qplus.beans.Session();
                //Qplus.Commands.GetFileCommand command_GetFile = new Qplus.Commands.GetFileCommand(
                //    l2c.UserID.ToString(), 
                //    System.Text.Encoding.UTF8.GetString(l2c.Key, 0, l2c.Key.Length),
                //    session,
                //    (long)friendList.userList[i].headType,
                //    friendList.userList[i].headValue);
                //command_GetFile.set(friendList.userList[i].headValue);
                //command_GetFile.execute(l2c.UpgradeURL);
                #endregion
                //friend.setUserID(friendListArr[i].userID);
                //command_GetFriend.set(friend.getUserID());
                //command_GetFriend.execute(l2c.UpgradeURL);

                fList.Add(new FriendControl()
                {
                    CtrlType = friendCtrlTypeEnum.friend,
                    UserID = userNode.Value.userID,
                    UserName = userNode.Value.userName,
                    UserLevel = userNode.Value.userLevel,
                    HeadType = userNode.Value.headType,
                    HeadValue = userNode.Value.headValue
                });
                userNode = userNode.Next;
                //friendList.Add(new friend()
                //{
                //    type = friendCtrlTypeEnum.friend,
                //    userID = friendListArr[i].userID,
                //    userName = friendListArr[i].userName,
                //    userLevel = friendListArr[i].userLevel,
                //    headType = friendListArr[i].headType,
                //    headValue = friendListArr[i].headValue
                //});
            }
            return true;
        }
        private void addFriend(object sender, RoutedEventArgs e)
        { }
        private void delFriend(object sender, RoutedEventArgs e)
        {
            ButtonEx tmp = sender as ButtonEx;
            Grid tmpGrid = tmp.Parent as Grid;
            FriendControl tmpFriendControl = tmpGrid.Parent as FriendControl;
            friendLklst.Remove(tmpFriendControl);
        }
        #endregion
        #region CHATROOM
        public LinkedList<ChatRoomControl> chatroomLklst = new LinkedList<ChatRoomControl>();
        CreateChatroomControl newCreateChatroom;
        PopupContainer pc;
        public bool createChatRoomList()
        {
            //System.IO.IsolatedStorage.IsolatedStorageSettings settings = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings;
            //settings.TryGetValue<room[]>("roomList", out roomListArr);
            var roomNode=uidata.roomList.list.First;
            while(null!=roomNode)
            {
                #region
                    //Qplus.Commands.GetResCommand command_GetRoomRes = new Qplus.Commands.GetResCommand(
                    //    friendList[i].userID.ToString(),
                    //    friendList[i].headValue);
                    //command_GetRoomRes.execute(l2c.UpgradeURL);
                    //Qplus.beans.Session session = new Qplus.beans.Session();
                    //Qplus.Commands.GetFileCommand command_GetFile = new Qplus.Commands.GetFileCommand(
                    //    l2c.UserID.ToString(), 
                    //    System.Text.Encoding.UTF8.GetString(l2c.Key, 0, l2c.Key.Length),
                    //    session,
                    //    (long)friendList.userList[i].headType,
                    //    friendList.userList[i].headValue);
                    //command_GetFile.set(friendList.userList[i].headValue);
                    //command_GetFile.execute(l2c.UpgradeURL);
                    #endregion
                rList.Add(new ChatRoomControl() {
                    CtrlType = chatroomCtrlTypeEnum.chatroom,
                    RoomID = roomNode.Value.roomID,
                    RoomName = roomNode.Value.roomName,
                    RoomLevel = roomNode.Value.roomLevel,
                    UserCount = roomNode.Value.userCount,
                    UpperLimit = roomNode.Value.upperLimit,
                    RoomHeadType = roomNode.Value.roomHeadType,
                    RoomHeadValue = roomNode.Value.roomHeadValue,
                    RoomHeat = roomNode.Value.roomHeat,
                    RoomPoint = roomNode.Value.roomPoint,
                });
                roomNode = roomNode.Next;
                //roomList.Add(new room()
                //{
                //    type = chatroomCtrlTypeEnum.create,
                //    roomID = roomListArr[j].roomID,
                //    roomName = roomListArr[j].roomName,
                //    roomLevel = roomListArr[j].roomLevel,
                //    userCount = roomListArr[j].userCount,
                //    upperLimit = roomListArr[j].upperLimit,
                //    roomHeadType = roomListArr[j].roomHeadType,
                //    roomHeadValue = roomListArr[j].roomHeadValue,
                //    roomHeat = roomListArr[j].roomHeat,
                //    roomPoint = roomListArr[j].roomPoint
                //});
            }
            return true;
        }
        private void createChatroomBtnEx_Click(object sender, RoutedEventArgs e)
        {
            newCreateChatroom = new CreateChatroomControl();
            newCreateChatroom.checkBtnEx.Click += checkBtnEx_Click;
            pc = new PopupContainer(this);
            pc.Show(newCreateChatroom);
        }
        void checkBtnEx_Click(object sender, RoutedEventArgs e)
        {
            ChatRoomControl newChatroom = new ChatRoomControl()
            {
                CtrlType = chatroomCtrlTypeEnum.chatroom,
                RoomName = newCreateChatroom.nameTxtBox.Text,
                HotStar = 1,
                bgColor = (SolidColorBrush)newCreateChatroom.LayoutRoot.Background
            };
            chatroomWP.Children.Add(newChatroom);
            //int i = chatroomGrid.Children.Count();
            //if (i % 2 == 0)
            {
                //chatroomGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(200) });
            }
            //Grid.SetRow(newChatroom, i / 2);
            //Grid.SetColumn(newChatroom, i % 2);
            //chatroomGrid.Children.Add(newChatroom);
            this.newCreateChatroom.CloseMeAsPopup();
        }
        #endregion
        #region STRANGER
        public LinkedList<FriendControl> strangeLklst = new LinkedList<FriendControl>();
        public bool createStrangerList(LinkedList<FriendControl> strangerLklst)
        {
            LinkedListNode<FriendControl> node = strangeLklst.First;
            for (; node != null; node = node.Next)
            {
                strangerWP.Children.Add(node.Value);
                
            }
            return true;
        }
        #endregion

        #region OTHER
        //refresh chatroom list
        private void refreshBtn_Click(object sender, RoutedEventArgs e)
        {

        }
//personalInfo
        private void personalInfoConfig_Click(object sender, RoutedEventArgs e)
        {
            System.ComponentModel.BackgroundWorker bw = new System.ComponentModel.BackgroundWorker();
            bw.DoWork += new System.ComponentModel.DoWorkEventHandler(bw_DoWork);
            bw.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
            bw.RunWorkerAsync();
        }
        void bw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            //throw new NotImplementedException();
            UIData.getInstance().GetUser();
            System.Threading.Thread.Sleep(1000);//do something
        }
        void bw_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/UI/PersonalSetting.xaml", UriKind.Relative));
        }
//close this page
        private void colseBtn_Click(object sender, RoutedEventArgs e)
        {
            if (NavigationService.CanGoBack)
            {
                NavigationService.GoBack();
            }
        }
        #endregion
#region
        //private void createFriendButton( int friendsNum)
        //            {
        //                int buttonNumber = friendsNum;

        //                RowDefinition rowDef = new RowDefinition();
        //                rowDef.Height = new GridLength( 200);
        //                friendsGrid.RowDefinitions.Add(rowDef);

        //                Grid.SetColumn(FriendBtnExBorder, 0);
        //                Grid.SetRow(FriendBtnExBorder, 0);
        //                Grid.SetColumn(friendNickNameBackground, 0);
        //                Grid.SetRow(friendNickNameBackground, 0);
        //                Grid.SetColumn(searchFriendBtnEx, 0);
        //                Grid.SetRow(searchFriendBtnEx, 0);
        //                //friendsGrid.Children.Add(FriendBtnExBorder);
        //                //friendsGrid.Children.Add(friendNickNameBackground);
        //                //friendsGrid.Children.Add(searchFriendBtnEx);

        //                //<Border Name="friendNickNameBackground" Height="40" Background="Gray" VerticalAlignment="Bottom" Margin="20"/>
            
        //                Border[] bdrArray = new Border[buttonNumber];
        //                Border[] txtBackground = new Border[buttonNumber];
        //                ButtonEx[] btnExArray = new ButtonEx[buttonNumber];
        //                for (i = 0; i < buttonNumber; i++)
        //                {
        //                    bdrArray[i] = new Border()
        //                    {
        //                        Margin = new Thickness(20),
        //                        Background = new SolidColorBrush(new Color() { A = 0xEB, R = 0x00, G = 0xE3, B = 0xFF })
        //                    };
        //                    txtBackground[i] = new Border()
        //                    {
        //                        Height = 40,
        //                        Margin = new Thickness(20),
        //                        VerticalAlignment = System.Windows.VerticalAlignment.Bottom,
        //                        Background = new SolidColorBrush(new Color() { A = 0xff, R = 0x80, G = 0x80, B = 0x80 })
        //                    };
        //                    ImageBrush imgBrh = new ImageBrush()
        //                    {
        //                        ImageSource = new BitmapImage(new Uri("/Qplus;component/Pic/icon_userhand_def.png", UriKind.RelativeOrAbsolute)),
        //                        Stretch = Stretch.None
        //                    };

        //                    btnExArray[i] = new ButtonEx()
        //                    {
        //                        Content = "Friend" + i.ToString(),
        //                        VerticalContentAlignment = System.Windows.VerticalAlignment.Bottom,
                    
        //                        PressedBorderBrush = new SolidColorBrush(new Color() { A = 0xff, R = 173, G = 216, B = 230 }),
        //                        BorderBrush = new SolidColorBrush(Colors.Transparent),
        //                        BorderThickness = new Thickness(8),
        //                        //Style = (Style)App.Current.Resources["buttonExStyle"],
        //                        Background = imgBrh,
        //                        PressedBackground = imgBrh
        //                    };
        //                    btnExArray[i].Click += FriendsBtn_Click;
                
        //                    Grid.SetColumn(bdrArray[i], (i + 1) % 2);
        //                    Grid.SetRow(bdrArray[i], (i + 1) / 2);
        //                    Grid.SetColumn(txtBackground[i], (i + 1) % 2);
        //                    Grid.SetRow(txtBackground[i], (i + 1) / 2);
        //                    Grid.SetColumn(btnExArray[i], (i + 1) % 2);
        //                    Grid.SetRow(btnExArray[i], (i + 1) / 2);
        //                    if (i % 2 != 0)
        //                    {
        //                        RowDefinition rowDef1 = new RowDefinition();
        //                        rowDef1.Height = new GridLength(200);
        //                        friendsGrid.RowDefinitions.Add(rowDef1);
        //                    }
        //                    friendsGrid.Children.Add(bdrArray[i]);
        //                    friendsGrid.Children.Add(txtBackground[i]);
        //                    friendsGrid.Children.Add(btnExArray[i]);
        //                }
        //            }
        //private void createChatroomButton(int chatroomNum)
        //            {
        //                int buttonNumber = chatroomNum;
        //                Random ra = new Random();

        //                Image hotStarImg = new Image()
        //                {
        //                    Source = new BitmapImage(new Uri("/Qplus;component/Pic/chatroom_hot.png", UriKind.RelativeOrAbsolute)),
        //                    Stretch = Stretch.None
        //                };

        //                RowDefinition rowDef = new RowDefinition();
        //                rowDef.Height = new GridLength(200);
        //                chatroomGrid.RowDefinitions.Add(rowDef);

        //                Grid.SetColumn(searchFriendBtnEx, 0);
        //                Grid.SetRow(searchFriendBtnEx, 0);

        //                ButtonEx[] btnArray = new ButtonEx[buttonNumber];
        //                Border[] bdrArray = new Border[buttonNumber];
        //                for (int i = 0; i < buttonNumber; i++)
        //                {
        //                    bdrArray[i] = new Border()
        //                    {
        //                        Margin = new Thickness(20),
        //                        Background = new SolidColorBrush(new Color() { A = byte.Parse((ra.Next(255)).ToString()), R = byte.Parse((ra.Next(255)).ToString()), G = byte.Parse((ra.Next(255)).ToString()), B = byte.Parse((ra.Next(255)).ToString()) })
        //                    };
        //                    Grid hotGrid = new Grid() { Height = 30, ShowGridLines = true, VerticalAlignment = System.Windows.VerticalAlignment.Bottom, Margin = new Thickness(20)};
        //                    ColumnDefinition colDef0 = new ColumnDefinition();
        //                    colDef0.Width = new GridLength(50);
        //                    ColumnDefinition colDef1 = new ColumnDefinition();
        //                    ColumnDefinition colDef2 = new ColumnDefinition();
        //                    ColumnDefinition colDef3 = new ColumnDefinition();
        //                    ColumnDefinition colDef4 = new ColumnDefinition();
        //                    ColumnDefinition colDef5 = new ColumnDefinition();
        //                    hotGrid.ColumnDefinitions.Add(colDef0);
        //                    hotGrid.ColumnDefinitions.Add(colDef1);
        //                    hotGrid.ColumnDefinitions.Add(colDef2);
        //                    hotGrid.ColumnDefinitions.Add(colDef3);
        //                    hotGrid.ColumnDefinitions.Add(colDef4);
        //                    hotGrid.ColumnDefinitions.Add(colDef5);
        //                    TextBlock hotTxtBlk = new TextBlock() { Text = "热度", Width = 50, Height = 30};
                

        //                    Grid.SetColumn(hotTxtBlk, 0);
        //                    hotGrid.Children.Add(hotTxtBlk);

        //                    int hotNum = 3;
        //                    Image[] hotStarImgArr = new Image[5];
        //                    for (int j = 0; j < hotNum; j++)
        //                    {
        //                        hotStarImgArr[j] = new Image();
        //                        hotStarImgArr[j].Source = hotStarImg.Source;
        //                        Grid.SetColumn(hotStarImgArr[j], j+1);
        //                        hotGrid.Children.Add(hotStarImgArr[j]);
        //                    }

        //                    btnArray[i] = new ButtonEx()
        //                    {
        //                        Content = "ChatRoom" + i.ToString(),
        //                        VerticalContentAlignment = System.Windows.VerticalAlignment.Top,

        //                        PressedBorderBrush = new SolidColorBrush(new Color() { A = 0xff, R = 173, G = 216, B = 230 }),
        //                        BorderBrush = new SolidColorBrush(Colors.Transparent),
        //                        BorderThickness = new Thickness(8),
        //                        //Style = (Style)App.Current.Resources["buttonExStyle"],
        //                        Background = new SolidColorBrush(Colors.Transparent),
        //                        PressedBackground = new SolidColorBrush(Colors.Transparent)
        //                    };
        //                        //ImageBrush imgBrh = new ImageBrush();
        //                    //imgBrh.ImageSource = new BitmapImage(new Uri("/Qplus;component/Pic/icon_create_chatroom_item.png", UriKind.RelativeOrAbsolute));
        //                    //imgBrh.Stretch = Stretch.None;
        //                    //btnArray[i].Background = imgBrh;
        //                    //btnArray[i].Background = new SolidColorBrush(Colors.Yellow);
        //                    //btnArray[i].Click += searchFriendsBtnEx_Click;

        //                    Grid.SetColumn(bdrArray[i], (i + 1) % 2);
        //                    Grid.SetRow(bdrArray[i], (i + 1) / 2);
        //                    Grid.SetColumn(hotGrid, (i + 1) % 2);
        //                    Grid.SetRow(hotGrid,(i + 1) / 2);
        //                    Grid.SetColumn(btnArray[i], (i + 1) % 2);
        //                    Grid.SetRow(btnArray[i], (i + 1) / 2);
        //                    if (i % 2 != 0)
        //                    {
        //                        RowDefinition rowDef1 = new RowDefinition();
        //                        rowDef1.Height = new GridLength(200);
        //                        chatroomGrid.RowDefinitions.Add(rowDef1);
        //                    }
        //                    chatroomGrid.Children.Add(bdrArray[i]);
        //                    chatroomGrid.Children.Add(hotGrid);
        //                    chatroomGrid.Children.Add(btnArray[i]);
        //                }
        //            }
        //private void getStrangerButtonEx(int StrangerNum)
        //            {
        //                int buttonNumber = StrangerNum;
        //                Random ra = new Random();

        //                RowDefinition rowDef = new RowDefinition();
        //                rowDef.Height = new GridLength(200);
        //                strangerGrid.RowDefinitions.Add(rowDef);

        //                Border[] bdrArray = new Border[buttonNumber];
        //                ButtonEx[] btnExArray = new ButtonEx[buttonNumber];
        //                for (i = 0; i < buttonNumber; i++)
        //                {
        //                    bdrArray[i] = new Border()
        //                    {
        //                        Margin = new Thickness(20),
        //                        Background = new SolidColorBrush(new Color() { A = byte.Parse((ra.Next(255)).ToString()), R = byte.Parse((ra.Next(255)).ToString()), G = byte.Parse((ra.Next(255)).ToString()), B = byte.Parse((ra.Next(255)).ToString()) })
        //                    };
        //                    ImageBrush imgBrh = new ImageBrush()
        //                    {
        //                        ImageSource = new BitmapImage(new Uri("/Qplus;component/Pic/icon_userhand_def.png", UriKind.RelativeOrAbsolute)),
        //                        Stretch = Stretch.None
        //                    };

        //                    btnExArray[i] = new ButtonEx()
        //                    {
        //                        Content = "Stranger" + i.ToString(),
        //                        VerticalContentAlignment = System.Windows.VerticalAlignment.Bottom,

        //                        PressedBorderBrush = new SolidColorBrush(new Color() { A = 0xff, R = 173, G = 216, B = 230 }),
        //                        BorderBrush = new SolidColorBrush(Colors.Transparent),
        //                        BorderThickness = new Thickness(8),
        //                        //Style = (Style)App.Current.Resources["buttonExStyle"],
        //                        Background = imgBrh,
        //                        PressedBackground = imgBrh
        //                    };
        //                    //btnExArray[i].Background = new SolidColorBrush(Colors.Blue);
        //                    //btnExArray[i].BorderBrush = new SolidColorBrush(Colors.Yellow);
        //                    //btnArray[i].Foreground = new SolidColorBrush(Colors.Red);
        //                    btnExArray[i].Click += FriendsBtn_Click;
        //                    //btnExArray[i].GotFocus += searchFriendsBtn_GotFocus;
        //                    //btnExArray[i].LostFocus += searchFriendsBtn_LostFocus;
        //                    //btnArray[i].Hold += searchFriendsBtn_Press;
        //                    //btnArray[i].KeyDown += searchFriendsBtn_Press;
        //                    //};
        //                    Grid.SetColumn(bdrArray[i], i % 2);
        //                    Grid.SetRow(bdrArray[i], i / 2);
        //                    Grid.SetColumn(btnExArray[i], i % 2);
        //                    Grid.SetRow(btnExArray[i], i / 2);
        //                    if (i % 2 != 0)
        //                    {
        //                        RowDefinition rowDef1 = new RowDefinition();
        //                        rowDef1.Height = new GridLength(200);
        //                        strangerGrid.RowDefinitions.Add(rowDef1);
        //                    }
        //                    strangerGrid.Children.Add(bdrArray[i]);
        //                    strangerGrid.Children.Add(btnExArray[i]);
        //                }
        //            }
#endregion
    }
}

